/*
 * @Author: your name
 * @Date: 2020-12-09 09:29:10
 * @LastEditTime: 2020-12-09 09:29:23
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /bridge-tunnel-ui/src/store/rest.js
 */
import request from '@/utils/request'
import requestForm from '@/utils/requestForm'

function requestAPI (options) { // json
  return new Promise((resolve, reject) => {
    request(options).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
}

function requestFormAPI (options) { // formdata
  return new Promise((resolve, reject) => {
    requestForm(options).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
}

const rest = {
  get: (url, data) => {
    return requestAPI({ url, method: 'get', params: data})
  },
  post: (url, data) => {
    return requestAPI({ url, method: 'post', data })
  },
  put: (url, data) => {
    return requestAPI({ url, method: 'put', data })
  },
  del: (url, data) => {
    return requestAPI({ url, method: 'delete', data })
  },
  getForm: (url, data) => {
    return requestFormAPI({ url, method: 'get', data })
  },
  postForm: (url, data) => {
    return requestFormAPI({ url, method: 'post', data })
  },
  delForm: (url, data) => {
    return requestFormAPI({ url, method: 'delete', data })
  },
  putForm: (url, data) => {
    return requestFormAPI({ url, method: 'put', data })
  }
}

export default rest